package com.example.loopyserver.server.impl;

import com.example.loopyserver.dto.LocationDTO;
import com.example.loopyserver.exception.CommonException;
import com.example.loopyserver.server.LocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.concurrent.ConcurrentHashMap;

@Service
@RequiredArgsConstructor
public class LocationServiceImpl implements LocationService {
    private final ConcurrentHashMap<String, LocationDTO> locationMap = new ConcurrentHashMap<>();

    @Override
    public LocationDTO getLocation(String key) throws CommonException {
        LocationDTO location = locationMap.get(key);
        if (location == null) {
            throw new CommonException();
        }
        return location;
    }

    @Override
    public void setLocation(String key, LocationDTO location) {
        locationMap.put(key, location);
    }
}
